//
//  MLBLEManager.h
//  喵喵屋
//
//  Created by 程杰 on 2020/11/11.
//  Copyright © 2020 cwq. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

NS_ASSUME_NONNULL_BEGIN

@interface MLBLEModel : NSObject

///开启配网标记，0X00（已配网）/0X01(cobo需要配网)/0x02（ble模块需要配网）直接配网
@property (nonatomic,assign) NSInteger mlApState;

/**
    0 -蓝牙名称是"MLink_"开头-6类型;
    1-广播协议6667开头-7类型;
    2-火星人FA蓝牙
 */
@property (nonatomic,assign) NSInteger bleType;

/// kind
@property (nonatomic,copy) NSString *mlKind;
/// model
@property (nonatomic,copy) NSString *mlModel;
/// 协议版本号
@property (nonatomic,copy) NSString *mlVersionCode;
///是否需要配网
@property (nonatomic,assign) BOOL isNeedNet;
/// 是否是妙联的蓝牙
@property (nonatomic,assign) BOOL isMLble;
/// 设备图片
@property (nonatomic,copy) NSString *netImg;
/// 设备名字
@property (nonatomic,copy) NSString *netName;
/// 搜索到的蓝牙名字
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *mac;
// 如阿里云：CodeStringValue
@property (nonatomic,copy) NSString *deviceName;
@property (nonatomic,strong) CBPeripheral *peripheral;
@property (nonatomic,strong) CBService *service;
//是否连接
@property (nonatomic,assign) BOOL connect;
//接收广播数据
@property (nonatomic,strong) NSDictionary *advertisementData;

@end


@class WQMLBleDeviceInfo;

typedef NS_ENUM(NSUInteger, MLBLEConnectState) {
    MLBLEConnectStateOvertime , // 超时
    MLBLEConnectStateBegin , // 进入连接状态
    MLBLEConnectStateSetupNetOk , // 已经配网过
    MLBLEConnectStateNone , // 未配网
    MLBLEConnectStateConnecting, // 配网中 4
    MLBLEConnectStateApSuccess, // 连接wifi成功  5
    MLBLEConnectStateSuccess, // 6连接成功
    MLBLEConnectStateError, // 连接失败
    MLBLEConnectStateDisconnect, // 外设断开连接
    MLBLEConnectStateConnectFail, // 连接外设失败
    MLBLEConnectStateUnKnow, // 模块返回状态未识别
};

/// 蓝牙信息model
typedef void (^mlBleDiscoverPeripheral )(MLBLEModel *model);
/// 妙联连接状态回调
typedef void (^mlBleConnectStateBlock)(MLBLEConnectState state);

@interface MLBLEManager : NSObject <CBCentralManagerDelegate,CBPeripheralDelegate>

/// 单例
+(instancetype)sharedManager;


/// 可选方法
/// @param isGet
- (void)isGetDeviceName:(BOOL)isGet;

/// 返回蓝牙model
/// @param callBack model
- (void)mlBleSearchCallBack:(mlBleDiscoverPeripheral )callBack;

/// 返回配网过程中的状态
/// @param callBack 蓝牙状态
- (void)mlBleConnectStateCallBack:(mlBleConnectStateBlock )callBack;

/// 初始化开始
- (void)mlBLeRun;
/// 扫描蓝牙
- (void)mlBleScan;
/// 停止扫描
- (void)mlBleStopScan;

- (MLBLEModel *)getCurrentModel;

/// 连接外设
/// @param model 蓝牙信息
/// @param overTime 超时时间，默认60秒，可不填
- (void)mlBleConnectCBPeripheralModel:(MLBLEModel *)model overTime:(int)overTime;

/// 返回从蓝牙广播中获取到信息
/// @param item 蓝牙广播数据
- (MLBLEModel *)getBleInfoWithBroadcast:(MLBLEModel *)item;

/// 发送wifi信息
/// @param wifiName wifi
/// @param passworld 密码
- (void)mlBleSmartConfigWifiName:(NSString *)wifiName passworld:(NSString *)passworld;

/// 写入数据,此方法暂不用
- (void)mlBleSendData:(NSData *)data;

/// 断开蓝牙
- (void)mlBleDisconnectPeripheral;


@end

NS_ASSUME_NONNULL_END
